﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Webcar.BLL;
using BusinessEntity;

namespace Webcar.Sec
{
    public partial class EditWinterReport : PageBase
    {
        string dept
        {
            get
            {
                return Request.QueryString["dept"];
            }
        }
        string ny
        {
            get
            {
                return Request.QueryString["ny"];
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.IsPostBack) return;
            DropDownListManager.BindDropDownDW(this.ddlDept);
            this.tbCheckDay.Text = DateTime.Now.ToString("yyyy-MM-dd");
            if (string.IsNullOrEmpty(dept)) return;
            this.LoadGpsSummary(dept, ny);
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                SEC_REPORT_WINTER entity = new SEC_REPORT_WINTER();

                entity.dept_code = this.ddlDept.SelectedValue;
                if (string.IsNullOrEmpty(entity.dept_code))
                {
                    this.lblError.Text = "请选择部门。";
                    return;
                }
                entity.check_day = this.tbCheckDay.Text;
                DateTime dt = DateTime.Now;
                if (DateTime.TryParse(this.tbCheckDay.Text, out dt) == false)
                {
                    this.lblError.Text = "日期格式错误。";
                    return;
                }
                if (entity.Retrieve() && string.IsNullOrEmpty(this.dept))
                {
                    this.lblError.Text = "该单位在本月已经存在记录，不能重复添加。";
                    return;
                }
                entity.czld = int.Parse(this.czld.Text);
                entity.cdjcry = int.Parse(this.cdjcry.Text);
                entity.jccl = int.Parse(this.jccl.Text);
                entity.jcry = int.Parse(this.jcry.Text);
                entity.clyh = int.Parse(this.clyh.Text);
                entity.ryyh = int.Parse(this.ryyh.Text);
                entity.glyh = int.Parse(this.glyh.Text);
                entity.fhl = int.Parse(this.fhl.Text);
                entity.sjm = int.Parse(this.sjm.Text);
                entity.tq = int.Parse(this.tq.Text);
                entity.qt = int.Parse(this.qt.Text);
                entity.aqjy = int.Parse(this.aqjy.Text);
                entity.jnpx = int.Parse(this.jnpx.Text);
                entity.gcsy = int.Parse(this.gcsy.Text);
                entity.gcly = int.Parse(this.gcly.Text);
                entity.scbcl = int.Parse(this.scbcl.Text);

                entity.Save();
                //跳转到中间页面
                this.GotoSucessPage("保存成功。", this.GetReturnUrl());
            }
            catch (FormatException)
            {
                this.lblError.Text = "你还有项目没有录入或者录入的数字格式错误。";
            }
            catch (Exception ex)
            {
                this.lblError.Text = "保存失败:" + ex.Message;
            }
        }

        void LoadGpsSummary(string dept, string ny)
        {
            if (string.IsNullOrEmpty(dept)) return;
            SEC_REPORT_WINTER entity = new SEC_REPORT_WINTER();
            entity.dept_code = dept;
            entity.check_day = ny;
            entity.Retrieve();
            this.ddlDept.SelectedValue = entity.dept_code;
            this.tbCheckDay.Text = entity.check_day;
            this.czld.Text = entity.czld.ToString();
            this.cdjcry.Text = entity.cdjcry.ToString();
            this.jccl.Text = entity.jccl.ToString();
            this.jcry.Text = entity.jcry.ToString();
            this.clyh.Text = entity.clyh.ToString();
            this.ryyh.Text = entity.ryyh.ToString();
            this.glyh.Text = entity.glyh.ToString();
            this.fhl.Text = entity.fhl.ToString();
            this.sjm.Text = entity.sjm.ToString();
            this.tq.Text = entity.tq.ToString();
            this.qt.Text = entity.qt.ToString();
            this.aqjy.Text = entity.aqjy.ToString();
            this.jnpx.Text = entity.jnpx.ToString();
            this.gcsy.Text = entity.gcsy.ToString();
            this.gcly.Text = entity.gcly.ToString();
            this.scbcl.Text = entity.scbcl.ToString();

        }
    }
}
